'use strict';
module.exports = app => {
  const { STRING, INTEGER, TINYINT } = app.Sequelize;
  const comptran = app.model.define(
      'comptran',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            beef: {type: INTEGER, allowNull: false, comment: '牛只'},
            nowcomp: {type: INTEGER, allowNull: false, comment: '当前所在场'},
            tocomp: {type: INTEGER, allowNull: false, comment: '目标转入场'},
            status: {type: STRING(20), allowNull: false, comment: '接收状态'},
            is_deleted: {type: TINYINT, defaultValue: 0, comment: '逻辑删除标识'},
      },
      {
          tableName: 'comptran',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: false, // 不想要 updatedAt
          createdAt: false, // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
    comptran.associate = function() {
        app.model.Comptran.belongsTo(app.model.BeefModel, {foreignKey: 'beef', targetKey: 'id'});
        app.model.Comptran.belongsTo(app.model.CompanyModel, {foreignKey: 'nowcomp', targetKey: 'id', as: 'nowCompany'});
        app.model.Comptran.belongsTo(app.model.CompanyModel, {foreignKey: 'tocomp', targetKey: 'id', as: 'toCompany'});
    }
    return comptran
};
